from langchain_openai import ChatOpenAI
from langchain.chains.llm import LLMChain
from langchain.prompts import ChatPromptTemplate
from langchain.chains.sequential import SimpleSequentialChain

api_key = "sk-6S0PtpNia71gjcfwSsDPsJ9mGqsVPr2XRQzAx1dHbJS7RW4t"
api_base="https://chatapi.littlewheat.com/v1"

prompt = ChatPromptTemplate.from_messages([
    ("system", "你是一位精通各领域知识的知名教授"),
        ("human", "请你尽可能详细的解释一下：{knowledge}")
])

llm = ChatOpenAI(model="gpt-3.5-turbo",api_key=api_key ,base_url=api_base)

chain = LLMChain(llm=llm,prompt=prompt,verbose=True)
#res = chain.invoke({"knowledge":"什么是LangChain？"})
#print(res)

prompt2 = ChatPromptTemplate([
("system", "你非常善于提取文本中的重要信息，并做出简短的总结"),
        ("human", "这是针对一个提问完整的解释说明内容：{description}"),
        ("human", "请你根据上述说明，尽可能简短的输出重要的结论，请控制在20个字以内")
])

chain2 = LLMChain(llm=llm,prompt=prompt2,verbose=True)

simple_chain = SimpleSequentialChain(chains=[chain,chain2],verbose=True)
final_response = simple_chain.invoke({"input":"什么是LangChain？"})
print(final_response)

